package com.neusoft.recommend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.recommend.domain.CourseRecommendFull;
import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.neusoft.recommend.domain.CourseRecommend;
import com.neusoft.recommend.service.ICourseRecommendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程推荐Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/courseSelect/recommend")
public class CourseRecommendController extends BaseController
{
    @Autowired
    private ICourseRecommendService courseRecommendService;

    /**
     * 查询课程推荐列表
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseRecommend courseRecommend)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        String role = loginUser.getUser().getRoles().get(0).getRoleName();

        if (role.equals("学生")) {
            courseRecommend.setStudentId(loginUser.getUsername());
        }

        List<CourseRecommend> list = courseRecommendService.selectCourseRecommendList(courseRecommend);
        return getDataTable(list);
    }

    /**
     * 查询课程推荐列表
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:recommend:list')")
    @GetMapping("/list-full")
    public TableDataInfo listFull(CourseRecommend courseRecommend)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        String role = loginUser.getUser().getRoles().get(0).getRoleName();

        if (role.equals("学生")) {
            courseRecommend.setStudentId(loginUser.getUsername());
        }

        List<CourseRecommendFull> list = courseRecommendService.selectFullCourseRecommendList(courseRecommend);
        return getDataTable(list);
    }

    /**
     * 导出课程推荐列表
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:recommend:export')")
    @Log(title = "课程推荐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseRecommend courseRecommend)
    {
        List<CourseRecommend> list = courseRecommendService.selectCourseRecommendList(courseRecommend);
        ExcelUtil<CourseRecommend> util = new ExcelUtil<CourseRecommend>(CourseRecommend.class);
        util.exportExcel(response, list, "课程推荐数据");
    }

    /**
     * 获取课程推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:recommend:query')")
    @GetMapping(value = "/{uuid}")
    public AjaxResult getInfo(@PathVariable("uuid") Long uuid)
    {
        return success(courseRecommendService.selectCourseRecommendByUuid(uuid));
    }

    /**
     * 新增课程推荐
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:recommend:add')")
    @Log(title = "课程推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseRecommend courseRecommend)
    {
        return toAjax(courseRecommendService.insertCourseRecommend(courseRecommend));
    }

    /**
     * 修改课程推荐
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:recommend:edit')")
    @Log(title = "课程推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseRecommend courseRecommend)
    {
        return toAjax(courseRecommendService.updateCourseRecommend(courseRecommend));
    }

    /**
     * 删除课程推荐
     */
    @PreAuthorize("@ss.hasPermi('courseSelect:recommend:remove')")
    @Log(title = "课程推荐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uuids}")
    public AjaxResult remove(@PathVariable Long[] uuids)
    {
        return toAjax(courseRecommendService.deleteCourseRecommendByUuids(uuids));
    }
}
